﻿
Partial Class WebForm_Main_SearchBulletin
    Inherits System.Web.UI.UserControl


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            RaiseEvent Loaded(Me, New EventArgs)
        End If
    End Sub

    Protected Sub gvBulletin_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvBulletin.PageIndexChanging
        Me.gvBulletin.PageIndex = e.NewPageIndex
        Me.BindGV(Me.UserType)
    End Sub

    Protected Sub gvBulletin_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvBulletin.RowCommand
        If e.CommandName = "lknBulletinSubject" Then
            Dim row As GridViewRow = TryCast(TryCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            Dim key As DataKey = Me.gvBulletin.DataKeys(row.RowIndex)

            Me.AddBulletin1.Show(key("BulletinID"))
            'Me.upAddBulletin.Update()
        End If
    End Sub

    Protected Sub gvBulletin_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBulletin.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            'Me.reg()

            If DataBinder.Eval(e.Row.DataItem, "Topmost") = "Y" Then
                TryCast(e.Row.FindControl("muIssueDate"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwTopmost"), View))
            Else
                TryCast(e.Row.FindControl("muIssueDate"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwIssueDate"), View))
            End If

            'ScriptManager.GetCurrent(Me.Page).RegisterAsyncPostBackControl(e.Row.FindControl("lknBulletinSubject"))
        End If
    End Sub
End Class

Partial Class WebForm_Main_SearchBulletin
    Public Sub BindGV(ByVal userType As My.UserType)
        Me.UserType = userType

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("select b.* ")
        sql.AppendFormat("from Bulletin b ")
        sql.AppendFormat("where b.UserType in ('{0}', 'A') ", userType)
        sql.AppendFormat("order by case when b.Topmost = 'Y' then 1 else 2 end, b.CreateDate ")
        'MyObj.ShowMessage(Me.UserType)
        Me.gvBulletin.DataSource = dat.GetData(sql)
        Me.gvBulletin.DataBind()
    End Sub

    Private Property UserType() As My.UserType
        Get
            Return ViewState("UserType")
        End Get
        Set(ByVal value As My.UserType)
            ViewState("UserType") = value
        End Set
    End Property

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
End Class